<script type="text/javascript">
$(function(){
	var pg = App.base.appFileEdit.ui, pp = pg.params || {};

	var frm = {
		code: pg.seek('code'),
		name: pg.seek('name'),
		sourcePath: pg.seek('sourcePath'),
		deployPath: pg.seek('deployPath'),
		packPath: pg.seek('packPath'),
		type: pg.seek('type'),
		memo: pg.seek('memo')
	}
	
	frm.type.mac('combo', {
		width: 302,
		boxWidth: 302,
		data: Cache.base.file.type
	}).val(0);
	
	function getValues(){
		return {
			id: pg.params.id,
			appId: pg.params.appId,
 			parent: pg.params.parent,
 			projId: pg.params.projId,
			code: frm.code.val(),
			name: frm.name.val(),
			sourcePath: frm.sourcePath.val(),
			deployPath: frm.deployPath.val(),
			packPath: frm.packPath.val(),
			type: frm.type.selected[0],// 0-xml 1-properties 2-txt 3-其他类型
			memo: frm.memo.val()
		};
	}
	
	function setValues(o){
		pp.id=o.id;
		frm.code.val(o.code);
		frm.name.val(o.name);
		frm.sourcePath.val(o.sourcePath);
		frm.deployPath.val(o.deployPath);
		frm.packPath.val(o.packPath);
		frm.type.val(o.type);
		frm.memo.val(o.memo);
	}
	setValues(pp);
	
	function validate(p){
		var x = App.validate, v=App.base.validation,
		msg=pg.seek('msg').html('');
		b = x(v.app.code, p.code, msg, '英文编码')
			&& x(v.app.name, p.name, msg, '名字') 
// 			&& x(v.app.sourcePath, p.sourcePath, msg, '源码路径')
// 			& x('app.deployPath', frm.deployPath, p.deployPath)
// 			& x('app.packPath', frm.packPath, p.packPath);
		return b;
	}
	pg.find('input').blur(function(){
		var pms = getValues();
		if(!validate(pms))
			return;
	});
	pg.seek('ok').click(function(){
		var pms = getValues();
		if(!validate(pms))
			return;
		$.post(App.ctx + '/file/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data);//更新树	
				pg.close();
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	
	pg.seek('close').click(function(){
		pg.close();
	});

	if (pp.id) {
		var w = mac.wait('loading');
		$.get(App.ctx + '/file/get.do', {
			id : pp.id
		}, function(rs) {
			w.close();
			var ro = mac.eval(rs);
			if (ro.success) {
				setValues(ro.data);
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		}); 
	} else {
		setValues(pp);
	}
});
</script>
<div class="left">
	<div class="form">
		<div class="item">
			<span class="label">英文编号：</span>
			<input type="text" name="code" placeholder="请填入英文名字" />
			<span class="msg">*</span>
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">名字：</span> <input type="text" name="name"
				placeholder="请填入中文名字" /> <span class="msg">*</span>
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">源码路径：</span>
			<input type="text" name="sourcePath" placeholder="请填入源码路径" />
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">打包路径：</span>
			<input type="text" name="packPath" placeholder="请填入打包路径" />
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">部署路径：</span>
			<input type="text" name="deployPath" placeholder="请填入部署路径" />
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">类型：</span>
			<div class="combo" name="type"></div>
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">备忘录：</span>
			<textarea name="memo" placeholder="请填入memo"></textarea>
			<div class="clear"></div>
		</div>
		<div class="item">
			<span class="label">&nbsp;</span>
			<div name="msg" class="msg"></div>
			<div class="clear"></div>
		</div>
		<div class="bottom">
			<button name="ok" class="addBtn">确定</button>
			&nbsp;&nbsp;
			<button name="close" class="addBtn">取消</button>
		</div>
	</div>
</div>